package top.revery.task.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.RestController;
import top.revery.api.api.user.IUserPageWorksApi;
import top.revery.api.config.UserPageData;
import top.revery.api.entity.user.BaseUserKol;
import top.revery.api.entity.user.BaseUserPageWorks;
import top.revery.api.entity.user.BaseUserWorks;
import top.revery.api.entity.vo.BaseUserWorksVo;
import top.revery.task.dto.KolDto;
import top.revery.task.dto.UserPageWorksDto;
import top.revery.task.service.UserPageWorksService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author denghao
 * @title
 * @package
 * @date 2019/12/23 10:19
 */
@RestController
public class UserPageWorksController implements IUserPageWorksApi {
    @Autowired
    private UserPageWorksDto userPageWorksDto;
    @Autowired
    private KolDto kolDto;
    @Autowired
    private UserPageWorksService userPageWorksService;

    @Override
    public BaseUserPageWorks save(BaseUserPageWorks baseUserPageWorks) {

        try {
            return userPageWorksDto.save(baseUserPageWorks);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public UserPageData getList(int pageNum, int pageSize, Map map) {


        Page<BaseUserPageWorks> pageList = userPageWorksService.findPage(pageNum, pageSize, map);
        List<BaseUserPageWorks> content = pageList.getContent();

        UserPageData userPageData = new UserPageData();
        userPageData.list = content;
        userPageData.rows = pageList.getTotalElements();
        return userPageData;
    }


    //删除作品
    @Override
    public void delete(Long id) {
        try {
            userPageWorksDto.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void add(Long id) {

    }
}
